//
//  ConfirmOrderController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/20.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "ConfirmOrderController.h"
#import "ConfirmView.h"
#import "ShopSecondCell.h"
#import "ConfirmOrderCell.h"

#import "AddressManagerController.h"
#import "OrderPaymentController.h"

@interface ConfirmOrderController ()<UITableViewDelegate,UITableViewDataSource,ConfirmViewOrderDelagate>

@property(nonatomic,strong)UITableView *confirmOrderView;

@property (nonatomic,strong)ConfirmView *lastView;

@end

@implementation ConfirmOrderController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"确认订单";
    [self addUI];
}

- (void)addUI
{
    UITableView *confirmOrderView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,WIDTH, HEIGHT - HEIGHT / 9) style:UITableViewStyleGrouped];
    self.confirmOrderView = confirmOrderView;
    [self.view addSubview:confirmOrderView];
    confirmOrderView.delegate = self;
    confirmOrderView.dataSource = self;
    [self.view addSubview:confirmOrderView];
    
<<<<<<< HEAD
    ConfirmView *lastView = [[ConfirmView alloc] initWithFrame:CGRectMake(0,HEIGHT/9*8-64,WIDTH,HEIGHT/9)];
=======
    ConfirmView *lastView = [[ConfirmView alloc] initWithFrame:CGRectMake(0,HEIGHT * 0.8,WIDTH,HEIGHT/9)];
>>>>>>> d3592b511e827f55e5327fb3b6299cf02ab340d2
    lastView.delegate = self;
    [self.view addSubview:lastView];
}

//订单支付
- (void)confirmViewOrderDidClick:(UIButton *)button
{
    OrderPaymentController *OrderPaymentVC = [[OrderPaymentController alloc] init];
    [self.navigationController pushForm:self.navigationController pushToAndHidden:OrderPaymentVC];
}

#pragma mark>>>>>>>>DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else{
        return 5;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier= @"ConfirmOrderCellID";
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.font = FONT(15);
        cell.detailTextLabel.font = FONT(15);
    }
    
    if (indexPath.section == 0) {
        cell.textLabel.text = @"请填写收货地址";
        cell.imageView.image = [UIImage imageNamed:@"confirmOrder"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    }else if (indexPath.section == 1 && indexPath.row == 0){
        
        ConfirmOrderCell *confirmOrderCell = [tableView dequeueReusableCellWithIdentifier:@"ConfirmOrder"];
        if (confirmOrderCell == nil) {
            confirmOrderCell = [[ConfirmOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ConfirmOrder"];
        }
        return confirmOrderCell;
        
    }else{
        
        NSArray *arr = @[@"配送方式 : ",@"快递运费 : ",@"费率 : ",@"价格合计 : "];
        cell.textLabel.text = [NSString stringWithFormat:@"%@",arr[indexPath.row-1]];
        cell.detailTextLabel.text = @"快递";
        cell.textLabel.textColor = [UIColor grayColor];
    }

    return cell;
}

#pragma mark>>>>>>>>Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        AddressManagerController *AddressManagerVC = [[AddressManagerController alloc] init];
        [self.navigationController pushForm:self.navigationController pushToAndHidden:AddressManagerVC];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==0) {
        return HEIGHT/10;
    }else if (indexPath.section == 1 && indexPath.row == 0){
    
#warning 为iPhone 7 留后路
        if (iPhone5) {
            return HEIGHT/6;
        }else if (iPhone6){
            return HEIGHT/6.5;
        }else{
            return HEIGHT/7;
        }
        
    }else{
        return HEIGHT/13;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.01;
    }else{
        return 10;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

@end
